/************************ (C) COPYLEFT 2010 Leafgrass *************************

* File Name          : stm32f10x_it.c
* Author             : Librae
* Last Modified Date : 08/19/2010
* Description        : Main Interrupt Service Routines.
*						This file provides template for all exceptions handler and
*						peripherals interrupt service routine.

******************************************************************************/

/* Includes -----------------------------------------------------------------*/

//#include "stm32f10x_it.h"
#include <stdio.h>
#include "..\gtlib\gtDev\STM32F10x\stm32f10x_lib.h"
#include "gtlib.h"

/* Private typedef ----------------------------------------------------------*/
/* Private define -----------------------------------------------------------*/
/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/

/* Private function prototypes ----------------------------------------------*/
/* Private functions --------------------------------------------------------*/

/*****************************************************************************/
/*            Cortex-M3 Processor Exceptions Handlers                        */
/*****************************************************************************/
extern void ETH_IRQHandler (void);//DM90000
/**
  * @brief   This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
// struct stack_contex
// {
// 	unsigned int r0;
// 	unsigned int r1;
// 	unsigned int r2;
// 	unsigned int r3;
// 	unsigned int r12;
// 	unsigned int lr;
// 	unsigned int pc;
// 	unsigned int psr;
// };
// char errMsg[32];
// void HardFault_Handler(struct stack_contex* contex)
// {

struct stack_contex
{
	u32 r0;
	u32 r1;
	u32 r2;
	u32 r3;
	u32 r12;
	u32 lr;
	u32 pc;
	u32 psr;
};

// char errMsg[32];
void HardFault_Exception(struct stack_contex* contex)
{
// 	//McuMonitor();	
// 	lcd_ClearAll(0);		
	
// 	bsp_ClearWDT();
// 	lcd_ClearAll(0);
	
	//gt_lcd_clearall(0);	
	//sprintf(errMsg,"HardFault:tsk%d",isr_tsk_get());
	//gui_DrawString_Mixed_Align(0, 60, errMsg, 0xFFFFFFFF, 0x20);	
	//sprintf(errMsg,"lr(%08x)",contex->lr);
	//gui_DrawString_Mixed_Align(0, 80, errMsg, 0xFFFFFFFF, 0x20);	
 //	gt_lcd_redraw();
	msg_out(" lr: 0x%08x\n", contex->lr);
	msg_out("psr: 0x%08x\n", contex->psr);
	msg_out(" pc: 0x%08x\n", contex->pc);
	msg_out("r12: 0x%08x\n", contex->r12);
	msg_out("r03: 0x%08x\n", contex->r3);
	msg_out("r02: 0x%08x\n", contex->r2);
	msg_out("r01: 0x%08x\n", contex->r1);
	msg_out("r00: 0x%08x\n", contex->r0);
	 // Go to infinite loop when Hard Fault exception occurs 

	msg_out("Hard Fault exception occurs...\n");
	  //wdg_Init();

	while (1)
	{
	}
/*
  // Go to infinite loop when Hard Fault exception occurs 
  printf("HardFault_Handler");
  while (1)
  {
  }
  */
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
void MemManage_Handler(void)
{
  /* Go to infinite loop when Memory Manage exception occurs */
   msg_out("MemManage_Handler");
//McuMonitor();
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
void BusFault_Handler(void)
{
  /* Go to infinite loop when Bus Fault exception occurs */
  msg_out("BusFault_Handler");
	//McuMonitor();
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
void UsageFault_Handler(void)
{
  /* Go to infinite loop when Usage Fault exception occurs */
  msg_out("UsageFault_Handler");
	//McuMonitor();
  while (1)
  {
  }
}


/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
void DebugMon_Handler(void)
{
}
/*
extern volatile unsigned int sys_nTime;
void SysTick_Handler(void)	
{
	if(sys_nTime != 0)
	{
		sys_nTime--;
	}
}
*/ 		
/*****************************************************************************/
/*                 STM32F10x Peripherals Interrupt Handlers                  */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/*  available peripheral interrupt handler's name please refer to the startup*/
/*  file (startup_stm32f10x_xx.s).                                           */
/*****************************************************************************/

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/

/**
  * @}
  */

/**
  * @brief  This function handles WWDG interrupt request.
  * @param  None
  * @retval None
  */
void WWDG_IRQHandler(void)
{
}

void PVD_IRQHandler(void)
{
}

void TAMPER_IRQHandler(void)
{
}

void RTC_IRQHandler(void)
{
}

void FLASH_IRQHandler(void)
{
}

void RCC_IRQHandler(void)
{
}

void EXTI0_IRQHandler(void)
{
}


void EXTI1_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line1)!= RESET)
	{	
		EXTI_ClearITPendingBit(EXTI_Line1); 
// 		ETH_IRQHandler();
	}
}

void EXTI2_IRQHandler(void)
{
}

void EXTI3_IRQHandler(void)
{
}

void EXTI4_IRQHandler(void)
{
}

void DMA1_Channel1_IRQHandler(void)
{

	if(DMA_GetITStatus(DMA1_IT_TC1))
	{
    	DMA_ClearITPendingBit(DMA1_IT_GL1);
	}
	
	if(DMA_GetITStatus(DMA1_IT_HT1))
	{
    	DMA_ClearITPendingBit(DMA1_IT_HT1);
	}


}

void DMA1_Channel2_IRQHandler(void)
{
}

void DMA1_Channel3_IRQHandler(void)
{
}

void DMA1_Channel4_IRQHandler(void)
{
}

void DMA1_Channel5_IRQHandler(void)
{
}

void DMA1_Channel6_IRQHandler(void)
{
}

void DMA1_Channel7_IRQHandler(void)
{
}

void ADC1_2_IRQHandler(void)
{
}

void USB_HP_CAN_TX_IRQHandler(void)
{
}

void USB_LP_CAN_RX0_IRQHandler(void)
{
}

void CAN_RX1_IRQHandler(void)
{
}

void CAN_SCE_IRQHandler(void)
{
}


void EXTI9_5_IRQHandler(void)
{	
	if(EXTI_GetITStatus(EXTI_Line7)!= RESET)
	{	
		EXTI_ClearITPendingBit(EXTI_Line7); 
// 		ETH_IRQHandler();
	}
	
	if(EXTI_GetITStatus(EXTI_Line9)!= RESET)
	{	
		EXTI_ClearITPendingBit(EXTI_Line9); 
// 		gt_151_rev();
	}	
	
}

void TIM1_BRK_IRQHandler(void)
{
}

void TIM1_UP_IRQHandler(void)
{
}

void TIM1_TRG_COM_IRQHandler(void)
{
}

void TIM1_CC_IRQHandler(void)
{
}

void TIM2_IRQHandler(void)
{

}

void TIM3_IRQHandler(void)
{
}

void TIM4_IRQHandler(void)
{
}

void I2C1_EV_IRQHandler(void)
{
}

void I2C1_ER_IRQHandler(void)
{
}

void I2C2_EV_IRQHandler(void)
{
}

void I2C2_ER_IRQHandler(void)
{
}

void SPI1_IRQHandler(void)
{
}

void SPI2_IRQHandler(void)
{
}

void USART1_IRQHandler(void)
{
	gt_uart_handler(0);

}


void USART2_IRQHandler(void)
{
	gt_uart_handler(1);

}


void USART3_IRQHandler(void)
{
	gt_uart_handler(2);
}

void EXTI15_10_IRQHandler(void)
{
}

void RTCAlarm_IRQHandler(void)
{
}

void USBWakeUp_IRQHandler(void)
{
}

void TIM8_BRK_IRQHandler(void)
{
}

void TIM8_UP_IRQHandler(void)
{
}

void TIM8_TRG_COM_IRQHandler(void)
{
}

void TIM8_CC_IRQHandler(void)
{
}

void ADC3_IRQHandler(void)
{
}

void FSMC_IRQHandler(void)
{
}

void SDIO_IRQHandler(void)
{
}

void TIM5_IRQHandler(void)
{
}

void SPI3_IRQHandler(void)
{
}

void UART4_IRQHandler(void)
{
	gt_uart_handler(3);
}

void UART5_IRQHandler(void)
{
	gt_uart_handler(4);
}

void TIM6_IRQHandler(void)
{
}

void TIM7_IRQHandler(void)
{
}

void DMA2_Channel1_IRQHandler(void)
{
}

void DMA2_Channel2_IRQHandler(void)
{
}

void DMA2_Channel3_IRQHandler(void)
{
}

void DMA2_Channel4_5_IRQHandler(void)
{
}

/*********************** (C) COPYLEFT 2010 Leafgrass *************************/
